package com.xxx.modules.controller;;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xxx.modules.entity.Archives;
import com.xxx.modules.entity.Comment;
import com.xxx.modules.entity.User;
import com.xxx.modules.service.HouseService;
import com.xxx.modules.entity.House;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import com.github.pagehelper.PageInfo;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import com.xxx.modules.utils.Result;
import com.xxx.modules.utils.ResultUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * house
 *
 * @author Mark 北易航
 * @since 1.0.0 2022-12-28
 */
@RestController
@RequestMapping("/common/house")
@Api(tags="house")
public class HouseController {
    @Autowired
    private HouseService houseService;

    /**
    *  获取所有住房信息
    * @param pageNum
    * @param pageSize
    * @param house
    * @return
    */

    @GetMapping("/getHouseInfo")
    @ApiOperation("获取所有住房信息")
    public Result getHouseInfo(House house, @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                      @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize){
        PageInfo<House> data = houseService.selectHouseInfo(house,pageNum,pageSize);


        return ResultUtil.success(1,"成功",data);
    }

    /**
    * 保存住房信息
    * @param house
    * @return
    */
    @PostMapping("/saveHouseInfo")
    @ApiOperation("保存住房信息")
    public Result saveHouseInfo(@RequestBody House house){
        houseService.saveHouseInfo(house);
        return ResultUtil.success(1,"成功",null);
    }


    /**
     * 更新住房信息
     * @param house
     * @return
     */

    @PutMapping("/updateHouseInfo")
    @ApiOperation("更新住房信息")
    public Result updateHouseInfo(@RequestBody House house){
        houseService.updateHouseInfo(house);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id删除住房信息
     * @param id
     * @return
     */
    @DeleteMapping("/delHouseInfo")
    @ApiOperation("根据id删除住房信息")
    public Result delHouseInfo(Integer id){
        houseService.delHouseInfo(id);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id集合批量删除住房信息
     * @param idList
     * @return
     */
    @DeleteMapping("/delBatchHouseInfo")
    @ApiOperation("根据id集合批量删除住房信息")
    public Result delBatchHouseInfo(String idList){
        houseService.delBatchHouseInfo(idList);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     *  绑定老人
     * @param archives
     * @return
     */
    @PutMapping("/houseId")
    public Result houseId(@RequestBody Archives archives){
        try {
            QueryWrapper<Archives> wrapper = new QueryWrapper<>();
            wrapper.eq("house_id",archives.getId());

            houseService.update(null,new LambdaUpdateWrapper<House>()
                    .set(House::getHouseId,archives.getId())
                    .eq(House::getId,archives.getId())) ;
            return ResultUtil.success(1,"正常",null);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.error(-1,"异常");
        }
    }

}